#!/bin/sh

# 定义文件夹路径
UPDATE_FOLDER="/home/bj/Downloads/bj-zsh-timer"

BACKGROUND_FOLDER="/usr/share/backgrounds"
BACKGROUND_IMG="/usr/share/backgrounds/background.png"



# 管理 gnome-extensions 扩展
gnome-extensions disable hide-dock-in-overview@roslax
gnome-extensions enable hide-dock-in-overview@roslax

gnome-extensions disable hidetopbar@mathieu.bidon.ca
gnome-extensions enable hidetopbar@mathieu.bidon.ca

gnome-extensions disable openbar@neuromorph
#gnome-extensions enable openbar@neuromorph


# 管理系统 Settings
# 检查当前设置

gsettings set org.gnome.shell.extensions.dash-to-dock dock-fixed false
#修改 Dock 图标大小
gsettings set org.gnome.shell.extensions.dash-to-dock dash-max-icon-size 1
# 关闭 Desktop Icons 的 Show Personalfolder
gsettings set org.gnome.shell.extensions.ding show-home false
# 设置屏幕关闭时间从不
gsettings set org.gnome.desktop.session idle-delay 0



if [ ! -d "$UPDATE_FOLDER" ]; then
    echo "The folder $UPDATE_FOLDER does not exist."
else
    # 检查文件夹是否为空
    if [ "$(ls -A "$UPDATE_FOLDER")" ]; then
        echo "$UPDATE_FOLDER is not empty. Deleting files..."
        echo 1|sudo -S rsync -a --remove-source-files "$UPDATE_FOLDER/" /usr/local/bin/
        # echo 1|sudo -S rm -rf /home/bj/Downloads/*
    else
        echo "$UPDATE_FOLDER is empty."
    fi
fi

/usr/bin/python3 /usr/local/bin/display_check_daemon.py > /home/bj/log/bj_timer/bj_display_check.log  &

echo 1|sudo -S systemctl restart bj_motor.service &
echo "bj_motor start success"

sleep 5

# 查看背景文件是否存在
if [ -f "$BACKGROUND_IMG" ]; then
    echo "File $BACKGROUND_IMG exists."
else
    echo "File $BACKGROUND_IMG does not exist."
    echo 1|sudo -S rm -rf /usr/share/backgrounds/*.png
    echo 1|sudo -S cp /usr/local/bin/background.png /usr/share/backgrounds
    sleep 1
    gsettings set org.gnome.desktop.background picture-uri 'file:///usr/share/backgrounds/background.png'
    echo 1|sudo -S ln -s /usr/share/backgrounds/background.png /usr/share/backgrounds/ubuntu-default-greyscale-wallpaper.png
fi


# 配置输入法切换
source /usr/local/bin/bj_input_config.sh

# 修改 硬件配置文件
# echo 1 | sudo -S change_firmware_config.sh


# cd /usr/local/bin && echo 1|sudo -S ./bj-timer > /home/bj/log/bj_timer/bj_timer.log &
cd /usr/local/bin && ./bj-timer > /home/bj/log/bj_timer/bj_timer.log &


echo 1|sudo -S ifconfig eth0 down
echo 1|sudo -S rm -rf /home/bj/Downloads/*

# 禁用Apport
echo 1|sudo -S systemctl disable apport.service
echo 1|sudo -S systemctl stop apport.service


# 检查当前是否连接到 Wi-Fi

wifi_connection=$(nmcli -t -f ACTIVE,SSID dev wifi | grep '^yes')


if [ -n "$wifi_connection" ]; then
    # 提取设备名称
        # 提取 SSID
    ssid=$(echo $wifi_connection | cut -d: -f2)
    
    # 显示连接的 Wi-Fi 网络名称
    echo "当前连接的 Wi-Fi 网络: $ssid"

    # 断开 Wi-Fi 连接
    nmcli device disconnect wlan0
    echo "已断开 Wi-Fi 连接: $ssid"
else
    echo "未连接到任何 Wi-Fi 网络"
fi


